import { request } from '@/utils/request';

// 房间状态枚举
export enum RoomStatus {
  AVAILABLE = 'available', // 空闲
  OCCUPIED = 'occupied', // 已住
  MAINTENANCE = 'maintenance', // 维修
  ACTIVE = 'active', // 活跃
  LOCKED = 'locked', // 锁定
}

// 支付状态枚举
export enum PaymentStatus {
  NORMAL = 'normal', // 正常
  OUTSTANDING = 'outstanding', // 欠费
  LEAVING_OUTSTANDING = 'leaving_outstanding', // 离欠
  GROUP_OUTSTANDING = 'group_outstanding', // 欠团
  LINKED_OUTSTANDING = 'linked_outstanding', // 欠联
}

// 房间类型接口
export interface RoomType {
  id: string;
  name: string;
  displayName: string;
}

// 房间数据接口
export interface RoomData {
  id: string;
  roomNumber: string;
  roomType: RoomType;
  status: RoomStatus;
  paymentStatus: PaymentStatus;
  occupantName?: string;
  checkInDate?: string;
  checkOutDate?: string;
  outstandingAmount?: number;
  notes?: string;
  building: string;
  floor: string;
  amenities: string[];
  specialIcons: string[];
  isHourlyLeaving?: boolean;
  isOvertime?: boolean;
}

// 筛选条件接口
export interface RoomFilter {
  building?: string;
  floor?: string;
  status?: RoomStatus;
  paymentStatus?: PaymentStatus;
}

// 统计数据接口
export interface RoomStatistics {
  overtimeCount: number;
  hourlyLeavingCount: number;
  occupancyRate: number;
  estimatedOccupancyRate: number;
  totalRooms: number;
  availableRooms: number;
  occupiedRooms: number;
  maintenanceRooms: number;
  outstandingRooms: number;
}

// 获取房间列表
export function getRoomList(params?: RoomFilter) {
  return request.get<RoomData[]>('/hotel/room/list', { params });
}

// 获取房间统计数据
export function getRoomStatistics() {
  return request.get<RoomStatistics>('/hotel/room/statistics');
}

// 获取楼栋列表
export function getBuildingList() {
  return request.get<{ label: string; value: string }[]>(
    '/hotel/building/list',
  );
}

// 获取楼层列表
export function getFloorList(buildingId?: string) {
  return request.get<{ label: string; value: string }[]>('/hotel/floor/list', {
    params: { buildingId },
  });
}

// 获取房间类型列表
export function getRoomTypeList() {
  return request.get<RoomType[]>('/hotel/room-type/list');
}

// 更新房间状态
export function updateRoomStatus(roomId: string, status: RoomStatus) {
  return request.put(`/hotel/room/${roomId}/status`, { status });
}

// 更新房间支付状态
export function updateRoomPaymentStatus(
  roomId: string,
  paymentStatus: PaymentStatus,
) {
  return request.put(`/hotel/room/${roomId}/payment-status`, { paymentStatus });
}

// 获取房间详情
export function getRoomDetail(roomId: string) {
  return request.get<RoomData>(`/hotel/room/${roomId}`);
}

// 刷新房间数据
export function refreshRoomData() {
  return request.post('/hotel/room/refresh');
}

// 打印房态表
export function printRoomStatusTable(params?: RoomFilter) {
  return request.post('/hotel/room/print', params);
}
